package com.lkm.app_ui.m.Imple.app_info;

import android.content.Intent;

import com.lkm.app_ui.AppConst;
import com.lkm.app_ui.RunTimeData;
import com.lkm.app_ui.jz.net.PayApi;
import com.lkm.app_ui.m.app_info.AppInfoScModule;
import com.lkm.frame.otto.LinkBus;
import com.lkm.frame.otto.ObserverAutoNext;
import com.lkm.market2_0.entity.SteelyardInfo;
import com.lkm.market2_0.m.steelyarddata.OnSteelardInfoLoadEvent;



public class AppInfoScModuleImpl implements AppInfoScModule {


    public AppInfoScModuleImpl() {

        regLoadSteelyardInfoTask();
    }

    @Override
    public void sendAppInfoBroadcast() {

        Intent intent = new Intent("com.lkm.action.AppInfo");
        intent.putExtra("pn", AppConst.getApplication().getPackageName());
        AppConst.getApplication().sendBroadcast(intent);
    }

    private void onSteelardInfoLoadEvent(SteelyardInfo steelyardInfo) {
        OnAppInfoTask task = new OnAppInfoTask(this, AppConst.getApplication().getPackageName(), steelyardInfo);
        task.action();
        task.execTask();

    }



    private void regLoadSteelyardInfoTask() {

        LinkBus.registerReceiver(new ObserverAutoNext<OnSteelardInfoLoadEvent>() {
            @Override
            public Class getBusEventClass() {
                return OnSteelardInfoLoadEvent.class;
            }

            @Override
            public void onReceiver(OnSteelardInfoLoadEvent data) {
                

                String meSteelyardMac = RunTimeData.steelyardInfo==null?"":RunTimeData.steelyardInfo.getSteelyardMac();

                if (meSteelyardMac != null && meSteelyardMac.equals(data.getSteelyardInfo().getSteelyardMac())) {
                    onSteelardInfoLoadEvent(data.getSteelyardInfo());
                }
                PayApi.getPayInfoFromSah();//初始化聚合配置。
            }
        });

    }
}
